﻿using System;

namespace CalcSharp.MDIUI.Dialogs
{
    public sealed class ConvolutionPreset
    {
        public short[,] ConvMatrix;
        public short Factor, Offset;
        public short this[int i, int j]
        {
            get { return this.ConvMatrix[i, j]; }
            set { this.ConvMatrix[i, j] = value; }
        }
    }

    public sealed class ConvolutonPresets
    {
        private ConvolutonPresets() { }

        public static ConvolutionPreset Blur
        {
            get
            {
                ConvolutionPreset ret = new ConvolutionPreset();
                ret.ConvMatrix = new short[3, 3];
                ret[0, 0] = 1; ret[0, 1] = 1; ret[0, 2] = 1;
                ret[1, 0] = 1; ret[1, 1] = 1; ret[1, 2] = 1;
                ret[2, 0] = 1; ret[2, 1] = 1; ret[2, 2] = 1;
                ret.Factor = 1;
                ret.Offset = 0;
                return ret;
            }
        }

        public static ConvolutionPreset GausianBlur
        {
            get
            {
                ConvolutionPreset ret = new ConvolutionPreset();
                ret.ConvMatrix = new short[3, 3];
                ret[0, 0] = 1; ret[0, 1] = 2; ret[0, 2] = 1;
                ret[1, 0] = 2; ret[1, 1] = 4; ret[1, 2] = 2;
                ret[2, 0] = 1; ret[2, 1] = 2; ret[2, 2] = 1;
                ret.Factor = 16;
                ret.Offset = 0;
                return ret;
            }
        }

        public static ConvolutionPreset Sharpen1
        {
            get
            {
                ConvolutionPreset ret = new ConvolutionPreset();
                ret.ConvMatrix = new short[3, 3];
                ret[0, 0] = 0; ret[0, 1] = -1; ret[0, 2] = 0;
                ret[1, 0] = -1; ret[1, 1] = 5; ret[1, 2] = -1;
                ret[2, 0] = 0; ret[2, 1] = -1; ret[2, 2] = 0;
                ret.Factor = 1;
                ret.Offset = 0;
                return ret;
            }
        }

        public static ConvolutionPreset Sharpen2
        {
            get
            {
                ConvolutionPreset ret = new ConvolutionPreset();
                ret.ConvMatrix = new short[3, 3];
                ret[0, 0] = 0; ret[0, 1] = -2; ret[0, 2] = 0;
                ret[1, 0] = -2; ret[1, 1] = 11; ret[1, 2] = -2;
                ret[2, 0] = 0; ret[2, 1] = -2; ret[2, 2] = 0;
                ret.Factor = 3;
                ret.Offset = 0;
                return ret;
            }
        }

        public static ConvolutionPreset MeanRemoval
        {
            get
            {
                ConvolutionPreset ret = new ConvolutionPreset();
                ret.ConvMatrix = new short[3, 3];
                ret[0, 0] = -1; ret[0, 1] = -1; ret[0, 2] = -1;
                ret[1, 0] = -1; ret[1, 1] = 9; ret[1, 2] = -1;
                ret[2, 0] = -1; ret[2, 1] = -1; ret[2, 2] = -1;
                ret.Factor = 1;
                ret.Offset = 0;
                return ret;
            }
        }
    }
}
